package com.huilai.platform.country_platform.repository;

import com.huilai.platform.country_platform.model.UserFeedback;
import com.huilai.platform.country_platform.model.UserRecruitment;
import com.huilai.platform.country_platform.model.VillageFeedback;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

/**
 * 作者：洪霓
 * 日期：2023/4/1
 * 注释：
 */
public interface UserFeedbackReposity extends JpaRepository<UserFeedback, Integer>, JpaSpecificationExecutor<UserFeedback> {
    @Modifying(clearAutomatically = true)
    @Transactional
    @Query(value = "insert into user_feedback(user_id, feedback_id) " +
            "values(:#{#userFeedback.userId}, :#{#userFeedback.feedbackId})", nativeQuery = true)
    Integer addUserFeedback(UserFeedback userFeedback);

    UserFeedback findUserFeedbackByFeedbackId(Integer feedbackId);

    @Modifying(clearAutomatically = true)
    @Transactional
    @Query(value = "update user_feedback uf set uf.deal_describe = :describe, " +
            "uf.unread = 1 where uf.id = :id",nativeQuery = true)
    Integer updateUserFeedback(Integer id, String describe);

    @Modifying(clearAutomatically = true)
    @Transactional
    @Query(value = "update user_feedback uf set uf.end_describe = :describe, " +
            "uf.unread = 1 where uf.id = :id",nativeQuery = true)
    Integer updateUserFeedback2(Integer id, String describe);
}
